package com.moran.deepseek.domain;

import cn.hutool.json.JSONUtil;
import lombok.Getter;
import lombok.Setter;

import java.io.Serial;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class ChatResult implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    private String code;      // 状态码
    private String msg;       // 描述信息
    private Object data;      // 返回数据

    public ChatResult() {}

    public ChatResult(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * <p>
     * description: 成功 - 无数据
     * </p>
     *
     * @author: bluefoxyu
     * @date: 2025-05-27 21:19:07
     */
    public static ChatResult success() {
        return new ChatResult("200", "成功", null);
    }


    /**
     * <p>
     * description: 成功 - 带数据
     * </p>
     *
     * @param data 需要响应的参数
     * @author: bluefoxyu
     * @date: 2025-05-27 21:19:25
     */
    public static ChatResult success(Object data) {
        return new ChatResult("200", "成功", data);
    }
    /**
     * <p>
     * description: 成功 - 自定义消息和数据
     * </p>
     *
     * @param msg 消息
     * @param data 数据
     * @author: bluefoxyu
     * @date: 2025-05-27 21:19:52
     */
    public static ChatResult success(String msg, Object data) {
        return new ChatResult("200", msg, data);
    }


    public static ChatResult success(String code, String msg, Object data) {
        return new ChatResult(code, msg, data);
    }



    public static ChatResult fail() {
        return new ChatResult("500", "系统异常，请联系管理员", null);
    }

    public static ChatResult fail(Object data) {
        return new ChatResult("500", "失败", data);
    }


    public static ChatResult fail(String msg, Object data) {
        return new ChatResult("500", msg, data);
    }

    public static ChatResult fail(String code, String msg, Object data) {
        return new ChatResult(code, msg, data);
    }



    public ChatResult data(String key, Object value) {
        Map<String, Object> map = new HashMap<>();
        map.put(key, value);
        this.data = map;
        return this;
    }

    public String toJson() {
        return JSONUtil.toJsonStr(this);
    }
}